package model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import util.SimpleObject;

@XmlRootElement
public class Benh extends ChuDe{
	private LoaiBenh loaiBenh;
	private String nguyenNhan;
	private String trieuChung;
	private String chanDoan;
	private String cachChuaTriTayY;
	private String cachChuaTriDongY;
	private Set<Thuoc> dsThuocChua;
	private Set<BacSi> dsBacSiChuyen;
	private Set<DiaDiemYTe> dsDiaDiemYTeChuyen;
	private String phongChongBenh;
	
	public Benh(){}
	
	public Benh(String tenChuDe, ChuDe chuDeCha, LoaiBenh loaiBenh, String nguyenNhan, String trieuChung,
			String chanDoan, String cachChuaTriTayY, String cachChuaTriDongY, String phongChongBenh) {
		super(tenChuDe, chuDeCha, chuDeCha.loai);
		this.loaiBenh = loaiBenh;
		this.nguyenNhan = nguyenNhan;
		this.trieuChung = trieuChung;
		this.chanDoan = chanDoan;
		this.cachChuaTriTayY = cachChuaTriTayY;
		this.cachChuaTriDongY = cachChuaTriDongY;
		this.dsThuocChua = new HashSet<Thuoc>();
		this.dsBacSiChuyen = new HashSet<BacSi>();
		this.dsDiaDiemYTeChuyen = new HashSet<DiaDiemYTe>();
		this.phongChongBenh = phongChongBenh;
	}
	
	public void setLazy() {
		for (Thuoc thuoc : dsThuocChua) {
			thuoc.setDsBenh(new HashSet<Benh>());
		}
		for (DiaDiemYTe ddyt : dsDiaDiemYTeChuyen) {
			ddyt.setDsChuyenKhoa(new HashSet<ChuyenKhoa>());
			ddyt.setDsBacSi(new HashSet<BacSi>());
			ddyt.setDsBenhChuyen(new HashSet<Benh>());
		}
		for (BacSi bacSi : dsBacSiChuyen) {
			bacSi.setDsBenhChuyen(new HashSet<Benh>());
			bacSi.getNoiCongTac().setDsChuyenKhoa(new HashSet<ChuyenKhoa>());
			bacSi.getNoiCongTac().setDsBacSi(new HashSet<BacSi>());
			bacSi.getNoiCongTac().setDsBenhChuyen(new HashSet<Benh>());
		}
	}
	
	public void addThuocChua(Thuoc thuoc){
		dsThuocChua.add(thuoc);
		thuoc.addBenh(this);
	}
	
	public void removeThuocChua(Thuoc thuoc){
		dsThuocChua.remove(thuoc);
//		thuoc.removeBenh(this);
	}
	
	public void addDiaDiemYTe(DiaDiemYTe diaDiemYTe) {
		dsDiaDiemYTeChuyen.add(diaDiemYTe);
		diaDiemYTe.addBenhChuyen(this);
	}
	
	public void removeDiaDiemYTe(DiaDiemYTe diaDiemYTe){
		dsDiaDiemYTeChuyen.remove(diaDiemYTe);
	}
	
	public void addBacSi(BacSi bacSi) {
		dsBacSiChuyen.add(bacSi);
		bacSi.addBenh(this);
	}
	
	public void removeBacSi(BacSi bacSi){
		dsBacSiChuyen.remove(bacSi);
	}
	
	public LoaiBenh getLoaiBenh() {
		return loaiBenh;
	}
	
	public void setLoaiBenh(LoaiBenh loaiBenh) {
		this.loaiBenh = loaiBenh;
	}

	public String getNguyenNhan() {
		return nguyenNhan;
	}

	public void setNguyenNhan(String nguyenNhan) {
		this.nguyenNhan = nguyenNhan;
	}

	public String getTrieuChung() {
		return trieuChung;
	}

	public void setTrieuChung(String trieuChung) {
		this.trieuChung = trieuChung;
	}

	public String getChanDoan() {
		return chanDoan;
	}

	public void setChanDoan(String chanDoan) {
		this.chanDoan = chanDoan;
	}

	public String getCachChuaTriTayY() {
		return cachChuaTriTayY;
	}

	public void setCachChuaTriTayY(String cachChuaTriTayY) {
		this.cachChuaTriTayY = cachChuaTriTayY;
	}

	public String getCachChuaTriDongY() {
		return cachChuaTriDongY;
	}

	public void setCachChuaTriDongY(String cachChuaTriDongY) {
		this.cachChuaTriDongY = cachChuaTriDongY;
	}

	@XmlTransient
	public Set<Thuoc> getDsThuocChua() {
		return dsThuocChua;
	}
	
	@XmlElement(name="thuocChua")
	public List<SimpleObject> getDsSimpleThuocChua(){
		List<SimpleObject> result = new ArrayList<SimpleObject>();
		SimpleObject obj = null;
		for (Thuoc thuoc : dsThuocChua) {
			obj = new SimpleObject(thuoc.getIdChuDe(), thuoc.getTenChuDe());
			result.add(obj);
		}
		return result;
	}

	public void setDsThuocChua(Set<Thuoc> dsThuocChua) {
		this.dsThuocChua = dsThuocChua;
	}
	
	@XmlTransient
	public Set<BacSi> getDsBacSiChuyen() {
		return dsBacSiChuyen;
	}
	
	@XmlElement(name="bacSiChuyen")
	public List<SimpleObject> getDsIdBacSiChuyen(){
		List<SimpleObject> result = new ArrayList<SimpleObject>();
		SimpleObject obj = null;
		for (BacSi bacSi : dsBacSiChuyen) {
			obj = new SimpleObject(bacSi.getIdChuDe(), bacSi.getTenChuDe());
			result.add(obj);
		}
		return result;
	}

	public void setDsBacSiChuyen(Set<BacSi> dsBacSiChuyen) {
		this.dsBacSiChuyen = dsBacSiChuyen;
	}

	@XmlTransient
	public Set<DiaDiemYTe> getDsDiaDiemYTeChuyen() {
		return dsDiaDiemYTeChuyen;
	}
	
	@XmlElement(name="diaDiemYTeChuyen")
	public List<SimpleObject> getDsSimpleDiaDiemYTeChuyen(){
		List<SimpleObject> result = new ArrayList<SimpleObject>();
		SimpleObject obj = null;
		for (DiaDiemYTe ddyt : dsDiaDiemYTeChuyen) {
			obj = new SimpleObject(ddyt.getIdChuDe(), ddyt.getTenChuDe());
			result.add(obj);
		}
		return result;
	}

	public void setDsDiaDiemYTeChuyen(Set<DiaDiemYTe> dsDiaDiemYTeChuyen) {
		this.dsDiaDiemYTeChuyen = dsDiaDiemYTeChuyen;
	}

	public String getPhongChongBenh() {
		return phongChongBenh;
	}

	public void setPhongChongBenh(String phongChongBenh) {
		this.phongChongBenh = phongChongBenh;
	}

	
	
}
